SciChart WPF 2D Charts > DataSeries API > DataSeries MultiThreading Considerations
DataSeries MultiThreading Considerations

Thread-Safety considerations

DataSeries may be modified on any thread; however, the follow thread-safety conditions should be noted.

DataSeries.SyncRoot

DataSeries includes a synchronisation object. All operations such as appending, updating, inserting, removing and clearing the data-series internally lock the DataSeries.SyncRoot.

DataSeries.SyncRoot
Copy Code
var xyDataSeries = new XyDataSeries<double,double>();

lock(xyDataSeries.SyncRoot)
{
    // Operate on the DataSeries
    var xRange = xyDataSeries.XRange;
}

DataSeries.SuspendUpdates()

DataSeries can also lock the entire parent chart, preventing redraws or updates until the operation is complete. To achieve this, wrap updates inside a DataSeries.SuspendUpdates() block:

DataSeries.SuspendUpdates()
Copy Code
var xyDataSeries = new XyDataSeries<double,double>();

using(xyDataSeries.SuspendUpdates())
{
    // Inside this block, the entire parent chart is locked
       // and cannot redraw
    xyDataSeries.Append(...);
       xyDataSeries.Append(...);
       xyDataSeries.Append(...);
} // One single redraw is performed at the end

NOTE: Considerations when a DataSeries is shared across multiple chart surfaces. Currently only a single parent chart is tracked, so DataSeries.SuspendUpdates() where the DataSeries is shared may have unexpected results.

Thread Contention with SuspendUpdates

Since DataSeries.SuspendUpdates() locks the parent chart, it should be noted that appending on a background thread and calling SuspendUpdates() frequently actually blocks drawing. It is therefore possible to get a high level of thread contention / blocking using this technique. It should be used sparingly.